package com.hisw.modules.api.controller;

import com.hisw.common.utils.R;
import com.hisw.common.utils.RedisUtils;
import com.hisw.modules.api.dao.UserDao;
import com.hisw.modules.api.entity.UserEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping(value = "/api/hello")
@RestController
@Slf4j
public class ApiTestPaaSController {

    @Autowired
    private RedisUtils redisUtils;

    @Autowired
    private UserDao userDao;

    @RequestMapping(value = "/cache/{param}")
    public R testCacheService(@PathVariable String param){

        redisUtils.set(param,param,30);
        log.info("Cache insert success,Cache key is {}",param);

        String cache = redisUtils.get(param);
        log.info("Cache get success,Cache value is {}",cache);

        return R.ok().put("cache value",cache);
    }

    @RequestMapping(value = "/database/{userId}")
    public R testDataBaseService(@PathVariable Long userId){
        UserEntity userEntity = userDao.selectById(userId);
        return R.ok().put("user object",userEntity);
    }


}
